package com.atguigu.boot.controller;

import com.atguigu.boot.bean.Person;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
public class ParameterTestController {



    @PostMapping("/testPOJO")
    public Person getPerson(Person person){
        return person;
    }






    @GetMapping("/user/{id}/owner/{username}")
    public Map testParam(@PathVariable("id") Integer id,
                                        @PathVariable("username") String name,
                                        @PathVariable Map<String,String> stringMap,
                                        @RequestHeader("Host") String host,
                                        @RequestHeader Map<String,String> hosts,
                                        @RequestParam("age") Integer age,
                                        @RequestParam("its") List<String> its
//                                        @CookieValue Map<String,String> cookies

                                        ){
        HashMap<String, Object> map = new HashMap<>();

        map.put("id",id);
        map.put("username",name);
        map.put("map",stringMap);

        map.put("host",host);
        map.put("hosts",hosts);

        map.put("age",age);
        map.put("all",its);
//        map.put("cokies",cookies);

        return map;
    }


    @PostMapping("/testRequest")
    public Map testRequest(@RequestBody String content){

        HashMap<String, Object> map = new HashMap<>();
        map.put("content",content);

        return map;
    }

    /**
     * //1、语法： 请求路径：
     *路径配置的规则方法:configurePathMatch,
     *     //2、SpringBoot默认是禁用了矩阵变量的功能
     *
     *     //      手动开启：原理。对于路径的处理。UrlPathHelper进行解析。
     *
     *     //              removeSemicolonContent（移除分号内容）支持矩阵变量的
     *
     *     //3、矩阵变量必须有url路径变量才能被解析
     * @param low
     * @return
     */

    @RequestMapping("/cars/{path}")
    public Map testMatrixVariable(@MatrixVariable("low") Integer low,
                                  @MatrixVariable("brand") List<String> brand){

        HashMap<String, Object> map = new HashMap<>();

        map.put("low",low);
        map.put("brand",brand);

        return map;
    }


    ///boos/1;age=19/2;age=22
//    @GetMapping("/boos/{boosId}/{empId}")
//    public Map boos(@MatrixVariable(value = "age",pathVar = "boosId") Integer boosAge,
//                    @MatrixVariable(value = "age" ,pathVar = "empId") Integer empAge){
//        HashMap<String, Object> map = new HashMap<>();
//
//        map.put("boosAge",boosAge);
//        map.put("empAge",empAge);
//
//        return map;
//    }


    // /boss/1;age=20/2;age=10


    @GetMapping("/boss/{bossId}/{empId}")

    public Map boss(@MatrixVariable(value = "age",pathVar = "bossId") Integer bossAge,

                    @MatrixVariable(value = "age",pathVar = "empId") Integer empAge){

        Map<String,Object> map = new HashMap<>();


        map.put("bossAge",bossAge);

        map.put("empAge",empAge);

        return map;


    }

}
